<?php
include "../config.php";


class FacebookTestTest extends PHPUnit_Framework_TestCase
{
    protected static $facebook_test;
    
    public static function setUpBeforeClass(){
         
        $params = array(
                'appId'  => FB_APP_ID,
                'secret' => FB_APP_SECRET,
                'cookie' => true,
            );
        self::$facebook_test = new FacebookTest($params);
        self::$facebook_test->setDebugLevel(1);  
        self::$facebook_test->getAppAccessToken();
            
    }
    public static function tearDownAfterClass(){
        self::$facebook_test = null;
    }
        
    function setUp() {}
    function tearDown() {}
    
    
    public function testInitialization(){
        $this->assertNotNull(self::$facebook_test);
    }
    public function testGetAppAccessToken(){
        $this->assertContains('access_token=',self::$facebook_test->getAppAccessToken());
    }
    public function testGetTestAccounts(){
        $accounts = self::$facebook_test->getTestAccounts();
        $this->assertNotNull($accounts);
    }      
    public function testDeleteAllTestAccounts(){
        //$this->assertNull(self::$facebook_test->deleteAllTestAccounts());
    }  

    /**
     * Test para la creacion de cuentas
     */         
    public function testCreateTestAccount(){
        $account = self::$facebook_test->createTestAccount();
        $this->assertNotNull($account);
        
        $fbID=$account['id'];
        $fbAccess_token=$account['access_token'];
        $fbLogin_url=$account['login_url'];
        $fbEmail=$account['email'];
        $fbPassword=$account['password'];

        $this->assertNotNull($fbID);
        $this->assertNotNull($fbAccess_token);
        $this->assertNotNull($fbLogin_url);
        $this->assertNotNull($fbEmail);
        $this->assertNotNull($fbPassword);
        
        return $account;
    }   

    /**
     * @depends testCreateTestAccount
     */         
    public function testFindTestAccount($account){
        $fbID=$account['id'];
        $this->assertNotNull($account2=self::$facebook_test->findTestAccount($fbID));
        $this->assertEquals($account['id'],$account2['id']);
        return $account;
    }
    
    /**
     * @depends testFindTestAccount
     */     
    public function testDeleteTestAccount($account){
        $fbID=$account['id'];
        self::$facebook_test->deleteTestAccount($fbID);
        $this->assertFalse(self::$facebook_test->findTestAccount($fbID));
    }            
            
    public function testAddFriends(){
        $accounts = self::$facebook_test->getTestAccounts();
        $count=count($accounts['data']);
        for($i=0;$i<$count-1;$i++){
            for($j=$i+1;$j<$count;$j++){
                $fbIdFrom=$accounts['data'][$i]['id'];
                $accessTokenFrom=$accounts['data'][$i]['access_token'];
                
                $fbIdTo=$accounts['data'][$j]['id'];
                $accessTokenTo=$accounts['data'][$j]['access_token'];
                
                self::$facebook_test->addFriends($fbIdFrom,$fbIdTo,$accessTokenFrom);
                self::$facebook_test->confirmFriends($fbIdFrom,$fbIdTo,$accessTokenTo);
                
            }
        }    
    }  
    
}